[id].vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <div>
  3. <breadCrumbs
  4. :main-menu="breadcrumbData.mainMenu"
  5. :current-sub-menu="breadcrumbData.currentSubMenu"
  6. :sub-menu-items="breadcrumbData.subMenuItems"
  7. />
  8. <div class="ovwner--wrapper">
  9. <div class="title--visual">
  10. <h2>PROMOTION</h2>
  11. </div>
  12. <div class="detail--container">
  13. <div class="content--wrap">
  14. <div v-if="loading" class="view--wrap">
  15. <p style="text-align: center; padding: 40px 0;">로딩 중...</p>
  16. </div>
  17. <div v-else-if="error" class="view--wrap">
  18. <p style="text-align: center; padding: 40px 0; color: red;">{{ error }}</p>
  19. </div>
  20. <div v-else-if="eventData" class="view--wrap">
  21. <div class="title--wrap">
  22. <h2>{{ eventData.title }}</h2>
  23. <div class="meta--info">
  24. <p>{{ formatDate(eventData.created_at) }}</p>
  25. <p v-if="eventData.start_date && eventData.end_date" class="event--period">
  26. 기간: {{ formatDate(eventData.start_date) }} ~ {{ formatDate(eventData.end_date) }}
  27. </p>
  28. </div>
  29. </div>
  30. <div class="cont--wrap">
  31. <div class="suneditor-content" v-html="eventData.content"></div>
  32. <!-- 링크 섹션 (Iron Auto only) -->
  33. <div v-if="config.public.company === 'i' && eventLinks.length > 0" class="event--links">
  34. <div class="link--title">관련 링크</div>
  35. <div class="link--buttons">
  36. <div v-for="(link, index) in eventLinks" :key="index" class="link--item">
  37. <a :href="link" target="_blank" rel="noopener noreferrer" class="link--button">
  38. <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
  39. <path d="M7.33333 8.66667L12.6667 3.33333M12.6667 3.33333H9.33333M12.6667 3.33333V6.66667M6.66667 2H4C3.46957 2 2.96086 2.21071 2.58579 2.58579C2.21071 2.96086 2 3.46957 2 4V12C2 12.5304 2.21071 13.0391 2.58579 13.4142C2.96086 13.7893 3.46957 14 4 14H12C12.5304 14 13.0391 13.7893 13.4142 13.4142C13.7893 13.0391 14 12.5304 14 12V9.33333" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
  40. </svg>
  41. {{ link }}
  42. </a>
  43. </div>
  44. </div>
  45. </div>
  46. <!-- <div v-if="fileLinks.length > 0" class="file--links">
  47. <div class="file--title">첨부파일</div>
  48. <div class="file--buttons">
  49. <div v-for="(link, index) in fileLinks" :key="index" class="file--item">
  50. <a :href="link.url" :target="link.target" class="file--button">
  51. <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
  52. <path d="M14 10v2.667A1.333 1.333 0 0 1 12.667 14H3.333A1.333 1.333 0 0 1 2 12.667V10m2.667-4L8 9.333 11.333 6M8 2v7.333" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
  53. </svg>
  54. {{ link.text }}
  55. </a>
  56. <span class="file--tooltip">{{ link.title }}</span>
  57. </div>
  58. </div>
  59. </div> -->
  60. </div>
  61. <!-- 이전글/다음글 -->
  62. <div class="post--navigation">
  63. <div class="nav--item prev" :class="{ disabled: !eventData.prev_post }">
  64. <NuxtLink v-if="eventData.prev_post" :to="`${isLincolnPage == false ? '/ford' : '/lincoln'}/owner/event/${eventData.prev_post.id}`" class="nav--link">
  65. <span class="nav--label">이전글</span>
  66. <span class="nav--title">{{ eventData.prev_post.title }}</span>
  67. </NuxtLink>
  68. <div v-else class="nav--link disabled">
  69. <span class="nav--label">이전글</span>
  70. <span class="nav--title">이전글이 없습니다.</span>
  71. </div>
  72. </div>
  73. <div class="nav--item next" :class="{ disabled: !eventData.next_post }">
  74. <NuxtLink v-if="eventData.next_post" :to="`${isLincolnPage == false ? '/ford' : '/lincoln'}/owner/event/${eventData.next_post.id}`" class="nav--link">
  75. <span class="nav--label">다음글</span>
  76. <span class="nav--title">{{ eventData.next_post.title }}</span>
  77. </NuxtLink>
  78. <div v-else class="nav--link disabled">
  79. <span class="nav--label">다음글</span>
  80. <span class="nav--title">다음글이 없습니다.</span>
  81. </div>
  82. </div>
  83. </div>
  84. <div class="btn--wrap" style="margin-top: 40px; text-align: center;">
  85. <button
  86. @click="goToList"
  87. class="btn--primary"
  88. style="padding: 12px 40px; background: #000; color: #fff; border: none; cursor: pointer;"
  89. >
  90. 목록으로
  91. </button>
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. </template>
  99. <script setup>
  100. const { getMediaUrl } = useImage();
  101. import { ref, computed, onMounted } from 'vue';
  102. import { useRoute, useRouter } from 'vue-router';
  103. import '~/assets/scss/suneditor-content.scss';
  104. const route = useRoute();
  105. const router = useRouter();
  106. const config = useRuntimeConfig();
  107. const { apiBase } = useCompany();
  108. const eventData = ref(null);
  109. const loading = ref(true);
  110. const error = ref(null);
  111. const isLincolnPage = computed(() => {
  112. return route.path.includes("lincoln");
  113. });
  114. // 파일명 자르기 함수 (20자 내외)
  115. const truncateFileName = (fileName) => {
  116. if (!fileName) return '';
  117. // 확장자 분리
  118. const lastDotIndex = fileName.lastIndexOf('.');
  119. const name = lastDotIndex > 0 ? fileName.substring(0, lastDotIndex) : fileName;
  120. const ext = lastDotIndex > 0 ? fileName.substring(lastDotIndex) : '';
  121. // 이름이 20자 이하면 그대로 반환
  122. if (name.length <= 20) {
  123. return fileName;
  124. }
  125. // 20자로 자르고 ... 추가 후 확장자 붙이기
  126. return name.substring(0, 20) + '...' + ext;
  127. };
  128. // 링크 목록 생성 (Iron Auto only)
  129. const eventLinks = computed(() => {
  130. if (!eventData.value || !eventData.value.link) return [];
  131. try {
  132. const links = Array.isArray(eventData.value.link)
  133. ? eventData.value.link
  134. : JSON.parse(eventData.value.link || '[]');
  135. // null이나 빈 문자열 제거
  136. return links.filter(link => link && link.trim() !== '');
  137. } catch (e) {
  138. console.error('링크 파싱 오류:', e);
  139. return [];
  140. }
  141. });
  142. // 파일 링크 목록 생성
  143. const fileLinks = computed(() => {
  144. if (!eventData.value || !eventData.value.file_urls) return [];
  145. try {
  146. const files = Array.isArray(eventData.value.file_urls)
  147. ? eventData.value.file_urls
  148. : JSON.parse(eventData.value.file_urls || '[]');
  149. return files.map(file => {
  150. let fileUrl = file.url || file;
  151. const originalFileName = file.name || file;
  152. // 상대 경로면 도메인 붙이기
  153. if (fileUrl.startsWith('/')) {
  154. fileUrl = apiBase.value + fileUrl;
  155. }
  156. return {
  157. text: truncateFileName(originalFileName),
  158. url: fileUrl,
  159. target: '_blank',
  160. class: 'pl--0',
  161. title: originalFileName // 툴팁으로 전체 파일명 표시
  162. };
  163. });
  164. } catch (e) {
  165. console.error('파일 파싱 오류:', e);
  166. return [];
  167. }
  168. });
  169. // 날짜 포맷팅
  170. const formatDate = (dateString) => {
  171. if (!dateString) return '-';
  172. const date = new Date(dateString);
  173. return `${date.getFullYear()}.${String(date.getMonth() + 1).padStart(2, '0')}.${String(date.getDate()).padStart(2, '0')}`;
  174. };
  175. // Event 데이터 로드
  176. const loadEventData = async () => {
  177. try {
  178. loading.value = true;
  179. error.value = null;
  180. const id = route.params.id;
  181. const response = await fetch(`${apiBase.value}/api/event/public/${id}`);
  182. const result = await response.json();
  183. console.log('[Event Detail] API 응답:', result);
  184. if (!result.success) {
  185. error.value = result.message || '이벤트 정보를 불러올 수 없습니다.';
  186. console.error('[Event Detail] API 에러:', result);
  187. } else if (result.data) {
  188. eventData.value = result.data;
  189. console.log('[Event Detail] 로드 성공:', eventData.value);
  190. } else {
  191. error.value = '이벤트 정보를 찾을 수 없습니다.';
  192. }
  193. } catch (e) {
  194. console.error('[Event Detail] 로드 실패:', e);
  195. error.value = '이벤트 정보를 불러오는 중 오류가 발생했습니다.';
  196. } finally {
  197. loading.value = false;
  198. }
  199. };
  200. // 목록으로 돌아가기
  201. const goToList = () => {
  202. router.push('/ford/owner/event');
  203. };
  204. // 샘플 데이터
  205. const breadcrumbData = {
  206. mainMenu: "OWNER",
  207. currentSubMenu: "프로모션",
  208. subMenuItems: [
  209. { label: "프로모션", to: '/ford/owner/event', active: false },
  210. ],
  211. };
  212. onMounted(() => {
  213. loadEventData();
  214. });
  215. </script>
  216. <style scoped lang="scss">
  217. .event--links {
  218. margin-top: 40px;
  219. padding-top: 24px;
  220. border-top: 1px solid rgba(252, 252, 253, 0.2);
  221. }
  222. .link--title {
  223. font-size: 16px;
  224. font-weight: 600;
  225. color: rgba(252, 252, 253, 1);
  226. margin-bottom: 16px;
  227. }
  228. .link--buttons {
  229. display: flex;
  230. flex-direction: column;
  231. gap: 12px;
  232. }
  233. .link--item {
  234. display: block;
  235. }
  236. .link--button {
  237. display: inline-flex;
  238. align-items: center;
  239. gap: 8px;
  240. padding: 12px 20px;
  241. background-color: rgba(255, 255, 255, 0.1);
  242. border: 1px solid rgba(252, 252, 253, 0.3);
  243. border-radius: 50px;
  244. color: rgba(252, 252, 253, 0.9);
  245. font-size: 14px;
  246. text-decoration: none;
  247. transition: all 0.3s ease;
  248. cursor: pointer;
  249. word-break: break-all;
  250. svg {
  251. flex-shrink: 0;
  252. }
  253. &:hover {
  254. background-color: rgba(255, 255, 255, 0.2);
  255. border-color: rgba(252, 252, 253, 0.5);
  256. transform: translateY(-2px);
  257. }
  258. &:active {
  259. transform: translateY(0);
  260. }
  261. }
  262. .file--links {
  263. margin-top: 40px;
  264. padding-top: 24px;
  265. border-top: 1px solid #444c57;
  266. }
  267. .file--title {
  268. font-size: 16px;
  269. font-weight: 600;
  270. color: rgba(252, 252, 253, 1);
  271. margin-bottom: 16px;
  272. }
  273. .file--buttons {
  274. display: flex;
  275. flex-wrap: wrap;
  276. gap: 12px;
  277. }
  278. .file--item {
  279. position: relative;
  280. display: inline-block;
  281. &:hover {
  282. .file--tooltip {
  283. opacity: 1;
  284. visibility: visible;
  285. transform: translateY(-5px);
  286. }
  287. }
  288. }
  289. .file--button {
  290. display: inline-flex;
  291. align-items: center;
  292. gap: 8px;
  293. padding: 12px 20px;
  294. background-color: rgba(255, 255, 255, 0.1);
  295. border: 1px solid rgba(252, 252, 253, 0.3);
  296. border-radius: 50px;
  297. color: rgba(252, 252, 253, 0.9);
  298. font-size: 14px;
  299. text-decoration: none;
  300. transition: all 0.3s ease;
  301. cursor: pointer;
  302. svg {
  303. flex-shrink: 0;
  304. }
  305. &:hover {
  306. background-color: rgba(255, 255, 255, 0.2);
  307. border-color: rgba(252, 252, 253, 0.5);
  308. transform: translateY(-2px);
  309. }
  310. &:active {
  311. transform: translateY(0);
  312. }
  313. }
  314. .file--tooltip {
  315. position: absolute;
  316. bottom: calc(100% + 10px);
  317. left: 50%;
  318. transform: translateX(-50%);
  319. background-color: rgba(0, 0, 0, 0.95);
  320. color: #fff;
  321. padding: 10px 14px;
  322. border-radius: 6px;
  323. font-size: 13px;
  324. white-space: nowrap;
  325. opacity: 0;
  326. visibility: hidden;
  327. transition: all 0.25s ease;
  328. pointer-events: none;
  329. z-index: 1000;
  330. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  331. &::after {
  332. content: '';
  333. position: absolute;
  334. top: 100%;
  335. left: 50%;
  336. transform: translateX(-50%);
  337. border: 7px solid transparent;
  338. border-top-color: rgba(0, 0, 0, 0.95);
  339. }
  340. }
  341. .file--item:hover .file--tooltip {
  342. transform: translateX(-50%) translateY(-5px);
  343. }
  344. </style>